<?php
/**
 * @package qBase
 * @subpackage model
 *
 */

/**
 * Represents an QStorage object
 * 
 * @package qBase
 * @subpackage model
 */
abstract class QStorage extends QStorageContainer 
{
	private static $Default;

	private $map_containers;

	public function __construct()
	{
		parent::__construct();
	}
	
	/**
	 * Function called to initialize the QStorage object
	 *
	 */
	public abstract function initStorage();
	
	/**
	 * Saves an object as a new item in the current QStorage object
	 *
	 * @param QIData $item
	 * @param mixed $container QStorageContainer or the string representation of the storage container
	 * @return QStorageId The storage id of the new object
	 */
	public abstract function create(QIData $item, $container = null);

	/**
	 * Loads data from the storage to the specified data object based on the id
	 *
	 * @param QStorageId $id
	 * @param mixed $container QStorageContainer or the string representation of the storage container
	 * @param array $properties_to_load The properties to load or null to use defaults
	 * @param QIData $item
	 * 
	 * @return QIData
	 */
	public abstract function load(QStorageId $id, $container = null, $properties_to_load = null, QIData $item = null);

	/**
	 * Loads data from the storage to the specified data object based on a query
	 *
	 * @param QSqlQuery $query
	 * @param mixed $container QStorageContainer or the string representation of the storage container
	 * @param array $properties_to_load
	 * @param QIData $item
	 * 
	 * @return QIData
	 */
	public abstract function loadOneFromQuery(QSqlQuery $query, $container = null, $properties_to_load = null, QIData $item = null);

	/**
	 * Loads data from the storage to the specified data object based on a query
	 *
	 * @param QSqlQuery $query
	 * @param mixed $container QStorageContainer or the string representation of the storage container
	 * @param array $properties_to_load
	 * 
	 * @return QDataArray
	 */
	public abstract function loadFromQuery(QSqlQuery $query, $container = null, $properties_to_load = null);

	/**
	 * Saves the object to the storage
	 *
	 * @param QIData $item
	 * @param array $properties_to_save Array of string
	 */
	public abstract function save(QIData $item, $properties_to_save = null);
	
	/**
	 * Deletes the object from the storage. If the object existed returns true
	 *
	 * @param QIData $item
	 * @return boolean
	 */
	public abstract function delete(QIData $item);
	
	/**
	 * Loads the specified properties for the specified object from the storage
	 *
	 * @param QIData $item
	 * @param array $properties_names
	 * @return array
	 */
	public abstract function loadProperties(QIData $item, $properties_names);

	/**
	 * Gets the default container for the specified class
	 *
	 * @param string $class_name
	 * @return QStorageContainer
	 */
	public abstract function getDefaultContainerForClass($class_name);
	/**
	 * Gets all storage containers 
	 *
	 * @return array
	 */
	public abstract function getAllContainers();

	/**
	 * Gets the default QStorage of the application
	 *
	 * @return QStorage
	 */
	public static function GetDefault()
	{
		return self::$Default;
	}
	
	/**
	 * Sets the default QStorage of the application
	 *
	 * @param QStorage $storage
	 */
	public static function SetDefault(QStorage $storage)
	{
		self::$Default = $storage;
	}
}

?>